package com.bsg.upm.check;

import java.text.MessageFormat;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpStatus;
import org.springframework.stereotype.Service;

import com.bsg.upm.constant.DictConstants;
import com.bsg.upm.constant.Messages;
import com.bsg.upm.entity.DefinitionSubServEntity;
import com.bsg.upm.entity.OrderEntity;

/**
 * 工单业务处理检查
 * 
 * @author HCK
 *
 */
@Service
public class OrderCheck extends BaseCheck {

	/**
	 * 新增时检查
	 * 
	 * @param paramMap
	 *            请求参数
	 * @return CheckResult检查结果
	 */
	public CheckResult checkSave(Map<String, Object> paramMap) {
		// 非逻辑检查
		CheckResult chkRS = checkSaveNonLogic(paramMap);
		if (chkRS.isError()) {
			return chkRS;
		}

		// 逻辑检查
		chkRS = checkSaveLogic(paramMap);
		if (chkRS.isError()) {
			return chkRS;
		}
		return chkRS;
	}

	/**
	 * 编辑时检查
	 * 
	 * @param paramMap
	 *            请求参数
	 * @return 检查结果
	 */
	public CheckResult checkUpdate(Map<String, Object> paramMap) {
		CheckResult chkRS = checkUpdateNonLogic(paramMap);
		if (chkRS.isError()) {
			return chkRS;
		}

		chkRS = checkUpdateLogic(paramMap);
		if (chkRS.isError()) {
			return chkRS;
		}
		return chkRS;
	}

	/**
	 * 克隆时检查
	 * 
	 * @param paramMap
	 *            请求参数
	 * @return 检查结果
	 */
	public CheckResult checkClone(OrderEntity order) {
		CheckResult chkRS = new CheckResult();
		// 存在性检查
		if (order == null) {
			chkRS.setStatus(HttpStatus.SC_GONE);
			chkRS.setErrorMsg(MessageFormat.format(Messages.NOT_EXIST, "工单"));
			return chkRS;
		}
		return chkRS;
	}

	/**
	 * 审批时检查
	 * 
	 * @param paramMap
	 *            请求参数
	 * @return CheckResult检查结果对象
	 */
	public CheckResult checkAudit(Map<String, Object> paramMap) {
		CheckResult chkRS = new CheckResult();
		if (!paramMap.containsKey("status")) {
			chkRS.setStatus(HttpStatus.SC_BAD_REQUEST);
			chkRS.setErrorMsg("工单审批请求参数错误");
			return chkRS;
		}

		String status = (String) paramMap.get("status");
		if (!DictConstants.ORDER_STATUS_APPROVED.equals(status)
				&& !DictConstants.ORDER_STATUS_UNAPPROVE.equals(status)) {
			chkRS.setStatus(HttpStatus.SC_BAD_REQUEST);
			chkRS.setErrorMsg("工单审批请求参数错误");
			return chkRS;
		}

		String msg = (String) paramMap.get("msg");
		if (DictConstants.ORDER_STATUS_UNAPPROVE.equals(status) && StringUtils.isBlank(msg)) {
			chkRS.setStatus(HttpStatus.SC_BAD_REQUEST);
			chkRS.setErrorMsg("审批拒绝时必须注明拒绝理由");
			return chkRS;
		}

		String orderId = (String) paramMap.get("orderId");
		OrderEntity order = orderDao.getBase(orderId);
		if (order == null) {
			chkRS.setStatus(HttpStatus.SC_GONE);
			chkRS.setErrorMsg(MessageFormat.format(Messages.NOT_EXIST, "工单"));
			return chkRS;
		}

		if (!DictConstants.ORDER_STATUS_UNAPPROVED.equals(order.getStatus())) {
			chkRS.setStatus(HttpStatus.SC_CONFLICT);
			chkRS.setErrorMsg("该工单已审批，不能重复审批");
			return chkRS;
		}
		return chkRS;
	}

	/**
	 * 执行时检查
	 * 
	 * @param paramMap
	 *            请求参数
	 * @return 检查结果
	 */
	public CheckResult checkExecute(OrderEntity order) {
		CheckResult chkRS = new CheckResult();
		if (order == null) {
			chkRS.setStatus(HttpStatus.SC_GONE);
			chkRS.setErrorMsg(MessageFormat.format(Messages.NOT_EXIST, "工单"));
			return chkRS;
		}

		if (!DictConstants.ORDER_STATUS_APPROVED.equals(order.getStatus())) {
			chkRS.setStatus(HttpStatus.SC_CONFLICT);
			chkRS.setErrorMsg("该工单未审批通过或已被执行，无法执行");
			return chkRS;
		}
		return chkRS;
	}

	/**
	 * 删除时检查
	 * 
	 * @param order
	 *            工单对象
	 * @return CheckResult检查结果对象
	 */
	public CheckResult checkRemove(OrderEntity order) {
		CheckResult chkRS = new CheckResult();

		// 存在性检查
		if (order == null) {
			chkRS.setStatus(HttpStatus.SC_GONE);
			chkRS.setErrorMsg(MessageFormat.format(Messages.NOT_EXIST, "工单"));
			return chkRS;
		}

		// 被关联工单检查
		if (orderDao.countBeAssociate(order.getId()) > 0) {
			chkRS.setStatus(HttpStatus.SC_CONFLICT);
			chkRS.setErrorMsg("该工单已被其他工单关联，无法删除");
			return chkRS;
		}

		// 关联服务检查
		if (servDao.countByOrderId(order.getId()) > 0) {
			chkRS.setStatus(HttpStatus.SC_CONFLICT);
			chkRS.setErrorMsg("该工单已关联服务，无法删除");
			return chkRS;
		}

		return chkRS;
	}

	/**
	 * 新增时非业务逻辑(非空和长度)检查
	 * 
	 * @param paramMap
	 *            请求参数
	 * @return CheckResult检查结果对象
	 */
	private CheckResult checkSaveNonLogic(Map<String, Object> paramMap) {
		CheckResult chkRS = new CheckResult();

		// // 服务定义非空检查
		// String dfServId = (String) paramMap.get("definitionServ");
		// if (StringUtils.isBlank(dfServId)) {
		// chkRS.setStatus(HttpStatus.SC_BAD_REQUEST);
		// chkRS.setErrorMsg(MessageFormat.format(Messages.NULL_NOT_ALLOWED,
		// "服务定义"));
		// return chkRS;
		// }
		//
		// // 所属站点非空检查
		// String siteId = (String) paramMap.get("site");
		// if (StringUtils.isBlank(siteId)) {
		// chkRS.setStatus(HttpStatus.SC_BAD_REQUEST);
		// chkRS.setErrorMsg(MessageFormat.format(Messages.NULL_NOT_ALLOWED,
		// "所属站点"));
		// return chkRS;
		// }
		//
		// // 服务名非空和长度检查
		// String servName = (String) paramMap.get("servName");
		// if (StringUtils.isBlank(servName)) {
		// chkRS.setStatus(HttpStatus.SC_BAD_REQUEST);
		// chkRS.setErrorMsg(MessageFormat.format(Messages.NULL_NOT_ALLOWED,
		// "服务名称"));
		// return chkRS;
		// }
		// if (servName.length() > 64) {
		// chkRS.setStatus(HttpStatus.SC_BAD_REQUEST);
		// chkRS.setErrorMsg(MessageFormat.format(Messages.MAXLENGTH_NOT_ALLOWED,
		// "服务名称"));
		// return chkRS;
		// }
		//
		// //
		// List<Map<String, Object>> dfSubServs_input = (List<Map<String,
		// Object>>) paramMap.get("definitionSubServs");
		// if (dfSubServs_input == null || dfSubServs_input.size() < 1) {
		// chkRS.setStatus(HttpStatus.SC_BAD_REQUEST);
		// chkRS.setErrorMsg("子服务定义结构体不存在");
		// return chkRS;
		// }
		//
		// for (Map<String, Object> map : dfSubServs_input) {
		// if (StringUtils.isBlank((String) map.get("name"))) {
		// chkRS.setStatus(HttpStatus.SC_BAD_REQUEST);
		// chkRS.setErrorMsg("子服务定义结构体错误：name不存在");
		// return chkRS;
		// }
		// }

		return chkRS;
	}

	private CheckResult checkSaveLogic(Map<String, Object> paramMap) {
		CheckResult chkRS = new CheckResult();
		// 服务定义存在性检查
		String dfServCode = (String) paramMap.get("definitionServ");
		List<DefinitionSubServEntity> dfSubServs = definitionSubServDao.listByDefinitionServCode(dfServCode);
		if (dfSubServs.size() == 0) {
			chkRS.setStatus(HttpStatus.SC_BAD_REQUEST);
			chkRS.setErrorMsg("服务定义不存在");
			return chkRS;
		}

		// 所属站点
		String siteId = (String) paramMap.get("site");
		if (siteDao.get(siteId) == null) {
			chkRS.setStatus(HttpStatus.SC_GONE);
			chkRS.setErrorMsg(MessageFormat.format(Messages.NOT_EXIST, "所属站点"));
			return chkRS;
		}

		// 服务名重复性检查
		String servName = (String) paramMap.get("servName");
		if (orderDao.countBySiteIdAndServName(siteId, servName) > 0) {
			chkRS.setStatus(HttpStatus.SC_CONFLICT);
			chkRS.setErrorMsg(MessageFormat.format(Messages.EXIST, "服务名称"));
			return chkRS;
		}

		// List<Map<String, Object>> dfSubServs_input = (List<Map<String,
		// Object>>) paramMap.get("definitionSubServs");
		// for (DefinitionSubServEntity dfSubServ : dfSubServs) {
		// boolean exist = false;
		// for (Map<String, Object> map : dfSubServs_input) {
		// if (dfSubServ.getName().equals(map.get("name"))) {
		// exist = true;
		// break;
		// }
		// }
		// if (!exist) {
		// chkRS.setStatus(HttpStatus.SC_BAD_REQUEST);
		// chkRS.setErrorMsg("服务定义结构体错误");
		// return chkRS;
		// }
		// }
		//
		// for (Map<String, Object> map : dfSubServs_input) {
		// boolean exist = false;
		// for (DefinitionSubServEntity dfSubServ : dfSubServs) {
		// if (dfSubServ.getName().equals(map.get("name"))) {
		// exist = true;
		// break;
		// }
		// }
		// if (!exist) {
		// chkRS.setStatus(HttpStatus.SC_BAD_REQUEST);
		// chkRS.setErrorMsg("服务定义结构体错误");
		// return chkRS;
		// }
		// }
		//
		// for (Map<String, Object> map : dfSubServs_input) {
		// String dfSubServName = (String) map.get("name");
		// // 架构检查（接入点即UPPROXY架构/URPROXY架构）
		// if (StringUtils.isBlank((String) map.get("arch"))) {
		// if (SysConstants.SUBSERV_UPSQL_NAME.equals(dfSubServName)
		// || SysConstants.SUBSERV_UPREDIS_NAME.equals(dfSubServName)) {
		// chkRS.setStatus(HttpStatus.SC_BAD_REQUEST);
		// chkRS.setErrorMsg(MessageFormat.format(Messages.NULL_NOT_ALLOWED,
		// "架构"));
		// return chkRS;
		// } else if (SysConstants.SUBSERV_UPPROXY_NAME.equals(dfSubServName)
		// || SysConstants.SUBSERV_URPROXY_NAME.equals(dfSubServName)) {
		// chkRS.setStatus(HttpStatus.SC_BAD_REQUEST);
		// chkRS.setErrorMsg(MessageFormat.format(Messages.NULL_NOT_ALLOWED,
		// "接入点"));
		// return chkRS;
		// }
		// } else {
		// String errorMsg = null;
		// if (SysConstants.SUBSERV_UPPROXY_NAME.equals(dfSubServName)
		// || SysConstants.SUBSERV_URPROXY_NAME.equals(dfSubServName)) {
		// errorMsg = MessageFormat.format(Messages.NOT_EXIST, dfSubServName +
		// "接入点");
		// } else {
		// errorMsg = MessageFormat.format(Messages.NOT_EXIST, dfSubServName +
		// "架构");
		// }
		// DefinitionSubServArchEntity arch =
		// definitionSubServArchDao.get((String) map.get("arch"));
		// if (arch == null ||
		// !arch.getDefinitionSubServ().getName().equals(dfSubServName)) {
		// chkRS.setStatus(HttpStatus.SC_GONE);
		// chkRS.setErrorMsg(errorMsg);
		// return chkRS;
		// }
		// }
		//
		// // 规模
		// if (StringUtils.isBlank((String) map.get("scale"))) {
		// if (SysConstants.SUBSERV_UPSQL_NAME.equals(dfSubServName)
		// || SysConstants.SUBSERV_UPREDIS_NAME.equals(dfSubServName)) {
		// chkRS.setStatus(HttpStatus.SC_BAD_REQUEST);
		// chkRS.setErrorMsg(MessageFormat.format(Messages.NULL_NOT_ALLOWED,
		// "规模"));
		// return chkRS;
		// }
		// } else {
		// DefinitionSubServUnitScaleEntity scale =
		// definitionSubServUnitScaleDao.get((String) map.get("scale"));
		// if (scale == null ||
		// !scale.getDefinitionSubServ().getName().equals(dfSubServName)) {
		// chkRS.setStatus(HttpStatus.SC_GONE);
		// chkRS.setErrorMsg(MessageFormat.format(Messages.NOT_EXIST,
		// dfSubServName + "规模"));
		// return chkRS;
		// }
		// }
		//
		// // 镜像版本
		// if (StringUtils.isBlank((String) map.get("softwareImage"))) {
		// if (SysConstants.SUBSERV_UPSQL_NAME.equals(dfSubServName)
		// || SysConstants.SUBSERV_UPREDIS_NAME.equals(dfSubServName)) {
		// chkRS.setStatus(HttpStatus.SC_BAD_REQUEST);
		// chkRS.setErrorMsg(MessageFormat.format(Messages.NULL_NOT_ALLOWED,
		// "软件版本"));
		// return chkRS;
		// }
		// } else {
		// SubServSoftwareImageEntity softwareImage = subServSoftwareImageDao
		// .get((String) map.get("softwareImage"));
		// if (softwareImage == null ||
		// !softwareImage.getDefinitionSubServSoftware().getDefinitionSubServName()
		// .equals(dfSubServName)) {
		// chkRS.setStatus(HttpStatus.SC_GONE);
		// chkRS.setErrorMsg(MessageFormat.format(Messages.NOT_EXIST,
		// dfSubServName + "软件版本"));
		// return chkRS;
		// }
		// }
		//
		// if (StringUtils.isBlank((String) map.get("dataDirDeviceType"))) {
		// if (SysConstants.SUBSERV_UPSQL_NAME.equals(dfSubServName)
		// || SysConstants.SUBSERV_UPREDIS_NAME.equals(dfSubServName)) {
		// chkRS.setStatus(HttpStatus.SC_BAD_REQUEST);
		// chkRS.setErrorMsg(MessageFormat.format(Messages.NULL_NOT_ALLOWED,
		// "数据类型"));
		// return chkRS;
		// }
		// }
		// }

		// String dfServId = (String) paramMap.get("definitionServId");
		// String siteId = (String) paramMap.get("siteId");
		// String servBusinessCode = StringUtils.trim((String)
		// paramMap.get("servBusinessCode"));
		// List<OrderEntity> orders =
		// orderDao.listBydfServIdAndServBusinessCodeAndSiteId(dfServId,
		// servBusinessCode,
		// siteId);
		//
		// if (orders.size() > 0) {
		// chkRS.setStatus(HttpStatus.SC_CONFLICT);
		// chkRS.setErrorMsg(MessageFormat.format(Messages.EXIST, "服务代码"));
		// return chkRS;
		// }
		//
		// String servBusinessName = StringUtils.trim((String)
		// paramMap.get("servBusinessName"));
		// UserEntity user = getUser();
		// String owner = user.getLoginName();
		// orders =
		// orderDao.listBydfServIdAndServBusinessNameAndSiteId(dfServId,
		// servBusinessName, owner, siteId);
		// if (orders.size() > 0) {
		// chkRS.setStatus(HttpStatus.SC_CONFLICT);
		// chkRS.setErrorMsg(MessageFormat.format(Messages.EXIST, "服务名称"));
		// return chkRS;
		// }
		//
		// String dfSubServArchId = (String)
		// paramMap.get("definitionSubServArchId");
		// DefinitionSubServArchEntity selectedDfSubServArch = null;
		// List<DefinitionSubServArchEntity> dfSubServArchs =
		// definitionSubServArchDao
		// .listPrimarySubServArchName(dfServId);
		// for (DefinitionSubServArchEntity dfSubServArch : dfSubServArchs) {
		// if (dfSubServArchId.equals(dfSubServArch.getId())) {
		// selectedDfSubServArch = dfSubServArch;
		// break;
		// }
		// }
		// if (selectedDfSubServArch == null) {
		// chkRS.setStatus(HttpStatus.SC_GONE);
		// chkRS.setErrorMsg(MessageFormat.format(Messages.NOT_EXIST, "服务架构"));
		// return chkRS;
		// }
		//
		// String dfSubServUnitScaleId = (String)
		// paramMap.get("definitionSubServUnitScaleId");
		// DefinitionSubServUnitScaleEntity selectedDfSubServUnitScale = null;
		// List<DefinitionSubServUnitScaleEntity> dfSubServUnitScales =
		// definitionSubServUnitScaleDao
		// .listPrimarySubServUnitScaleName(dfServId);
		// for (DefinitionSubServUnitScaleEntity dfSubServUnitScale :
		// dfSubServUnitScales) {
		// if (dfSubServUnitScaleId.equals(dfSubServUnitScale.getId())) {
		// selectedDfSubServUnitScale = dfSubServUnitScale;
		// break;
		// }
		// }
		// if (selectedDfSubServUnitScale == null) {
		// chkRS.setStatus(HttpStatus.SC_GONE);
		// chkRS.setErrorMsg(MessageFormat.format(Messages.NOT_EXIST, "性能规模"));
		// return chkRS;
		// }
		//
		// String subServSoftwareImageId = (String)
		// paramMap.get("subServSoftwareImageId");
		// SubServSoftwareImageEntity selectedSubServSoftwareImage = null;
		// Map<String, Object> pSubServImageParamMap = new HashMap<String,
		// Object>();
		// pSubServImageParamMap.put("siteId", siteId);
		// pSubServImageParamMap.put("definitionServId", dfServId);
		// List<SubServSoftwareImageEntity> subServSoftwareImages =
		// subServSoftwareImageDao
		// .listSubServSoftwareImageVersion(pSubServImageParamMap);
		// for (SubServSoftwareImageEntity subServSoftwareImage :
		// subServSoftwareImages) {
		// if (subServSoftwareImageId.equals(subServSoftwareImage.getId())) {
		// selectedSubServSoftwareImage = subServSoftwareImage;
		// break;
		// }
		// }
		// if (selectedSubServSoftwareImage == null) {
		// chkRS.setStatus(HttpStatus.SC_GONE);
		// chkRS.setErrorMsg(MessageFormat.format(Messages.NOT_EXIST, "软件版本"));
		// return chkRS;
		// }
		// if (!selectedSubServSoftwareImage.isEnabled()) {
		// chkRS.setStatus(HttpStatus.SC_GONE);
		// chkRS.setErrorMsg(MessageFormat.format(Messages.DISABLED_NOT_SELECT,
		// "软件版本"));
		// return chkRS;
		// }
		//
		// String networkBandwidth = (String) paramMap.get("networkBandwidth");
		// if
		// (dictDao.getByDictTypeCodeAndDictCode(DictTypeConstants.NETWORK_BANDWIDTH,
		// networkBandwidth) == null) {
		// chkRS.setStatus(HttpStatus.SC_GONE);
		// chkRS.setErrorMsg(MessageFormat.format(Messages.NOT_EXIST, "网络带宽"));
		// return chkRS;
		// }
		//
		// String dataDirDeviceType = (String)
		// paramMap.get("dataDirDeviceType");
		// if
		// (dictDao.getByDictTypeCodeAndDictCode(DictTypeConstants.DATA_DIR_TYPE,
		// dataDirDeviceType) == null) {
		// chkRS.setStatus(HttpStatus.SC_GONE);
		// chkRS.setErrorMsg(MessageFormat.format(Messages.NOT_EXIST,
		// "数据目录类型"));
		// return chkRS;
		// }
		//
		// Map<String, Object> areaMap = new HashMap<String, Object>();
		// areaMap.put("siteId", siteId);
		// areaMap.put("enabled", true);
		// List<AreaEntity> areas = areaDao.listName(areaMap);
		// if (areas.size() == 0) {
		// chkRS.setStatus(HttpStatus.SC_GONE);
		// chkRS.setErrorMsg("无可用区域");
		// return chkRS;
		// }

		return chkRS;
	}

	private CheckResult checkUpdateNonLogic(Map<String, Object> paramMap) {
		CheckResult chkRS = new CheckResult();

		String orderId = (String) paramMap.get("orderId");
		if (StringUtils.isBlank(orderId)) {
			chkRS.setStatus(HttpStatus.SC_BAD_REQUEST);
			chkRS.setErrorMsg(MessageFormat.format(Messages.NULL_NOT_ALLOWED, "工单"));
			return chkRS;
		}

		String servBusinessCode = (String) paramMap.get("servBusinessCode");
		if (StringUtils.isBlank(servBusinessCode)) {
			chkRS.setStatus(HttpStatus.SC_BAD_REQUEST);
			chkRS.setErrorMsg(MessageFormat.format(Messages.NULL_NOT_ALLOWED, "业务代码"));
			return chkRS;
		}
		if (StringUtils.trim(servBusinessCode).length() > 64) {
			chkRS.setErrorMsg(MessageFormat.format(Messages.MAXLENGTH_NOT_ALLOWED, "业务代码", 64));
			return chkRS;
		}

		String servBusinessName = (String) paramMap.get("servBusinessName");
		if (StringUtils.isBlank(servBusinessName)) {
			chkRS.setStatus(HttpStatus.SC_BAD_REQUEST);
			chkRS.setErrorMsg(MessageFormat.format(Messages.NULL_NOT_ALLOWED, "业务名称"));
			return chkRS;
		}
		if (StringUtils.trim(servBusinessName).length() > 64) {
			chkRS.setErrorMsg(MessageFormat.format(Messages.MAXLENGTH_NOT_ALLOWED, "业务名称", 64));
			return chkRS;
		}

		String dfSubServArchId = (String) paramMap.get("definitionSubServArchId");
		if (StringUtils.isBlank(dfSubServArchId)) {
			chkRS.setStatus(HttpStatus.SC_BAD_REQUEST);
			chkRS.setErrorMsg(MessageFormat.format(Messages.NULL_NOT_ALLOWED, "服务架构"));
			return chkRS;
		}

		String dfSubServUnitScaleId = (String) paramMap.get("definitionSubServUnitScaleId");
		if (StringUtils.isBlank(dfSubServUnitScaleId)) {
			chkRS.setStatus(HttpStatus.SC_BAD_REQUEST);
			chkRS.setErrorMsg(MessageFormat.format(Messages.NULL_NOT_ALLOWED, "性能规模"));
			return chkRS;
		}

		String subServSoftwareImageId = (String) paramMap.get("subServSoftwareImageId");
		if (StringUtils.isBlank(subServSoftwareImageId)) {
			chkRS.setStatus(HttpStatus.SC_BAD_REQUEST);
			chkRS.setErrorMsg(MessageFormat.format(Messages.NULL_NOT_ALLOWED, "软件版本"));
			return chkRS;
		}

		String networkBandwidth = (String) paramMap.get("networkBandwidth");
		if (StringUtils.isBlank(networkBandwidth)) {
			chkRS.setStatus(HttpStatus.SC_BAD_REQUEST);
			chkRS.setErrorMsg(MessageFormat.format(Messages.NULL_NOT_ALLOWED, "网络带宽"));
			return chkRS;
		}

		String dataDirDeviceType = (String) paramMap.get("dataDirDeviceType");
		if (StringUtils.isBlank(dataDirDeviceType)) {
			chkRS.setStatus(HttpStatus.SC_BAD_REQUEST);
			chkRS.setErrorMsg(MessageFormat.format(Messages.NULL_NOT_ALLOWED, "数据目录类型"));
			return chkRS;
		}

		Integer dataDirSize = (Integer) paramMap.get("dataDirSize");
		if (dataDirSize == null) {
			chkRS.setStatus(HttpStatus.SC_BAD_REQUEST);
			chkRS.setErrorMsg(MessageFormat.format(Messages.NULL_NOT_ALLOWED, "数据目录容量"));
			return chkRS;
		}
		if (dataDirSize < 1 || dataDirSize > 5000) {
			chkRS.setStatus(HttpStatus.SC_UNPROCESSABLE_ENTITY);
			chkRS.setErrorMsg(MessageFormat.format(Messages.BETWEEN_MIN_AND_MAX, "数据目录容量", 1, 5000));
			return chkRS;
		}

		Integer maxBackupSpace = (Integer) paramMap.get("maxBackupSpace");
		if (maxBackupSpace == null) {
			chkRS.setStatus(HttpStatus.SC_BAD_REQUEST);
			chkRS.setErrorMsg(MessageFormat.format(Messages.NULL_NOT_ALLOWED, "最大备份空间"));
			return chkRS;
		}
		if (maxBackupSpace < 1 || maxBackupSpace > 5000) {
			chkRS.setStatus(HttpStatus.SC_UNPROCESSABLE_ENTITY);
			chkRS.setErrorMsg(MessageFormat.format(Messages.BETWEEN_MIN_AND_MAX, "最大备份空间", 1, 5000));
			return chkRS;
		}

		Integer backupFilesRetention = (Integer) paramMap.get("backupFilesRetention");
		if (backupFilesRetention == null) {
			chkRS.setStatus(HttpStatus.SC_BAD_REQUEST);
			chkRS.setErrorMsg(MessageFormat.format(Messages.NULL_NOT_ALLOWED, "备份文件保留"));
			return chkRS;
		}
		if (maxBackupSpace < 0 || maxBackupSpace > 365) {
			chkRS.setStatus(HttpStatus.SC_UNPROCESSABLE_ENTITY);
			chkRS.setErrorMsg("备份文件保留天数不能超过365天");
			return chkRS;
		}

		return chkRS;
	}

	private CheckResult checkUpdateLogic(Map<String, Object> paramMap) {
		CheckResult chkRS = new CheckResult();
		// String orderId = (String) paramMap.get("orderId");
		// OrderEntity order = orderDao.getBase(orderId);
		// if (order == null) {
		// chkRS.setStatus(HttpStatus.SC_GONE);
		// chkRS.setErrorMsg(MessageFormat.format(Messages.NOT_EXIST, "工单"));
		// return chkRS;
		// }
		//
		// if (!DictConstants.ORDER_STATUS_UNAPPROVED.equals(order.getStatus())
		// && !DictConstants.ORDER_STATUS_UNAPPROVE.equals(order.getStatus())) {
		// chkRS.setStatus(HttpStatus.SC_CONFLICT);
		// chkRS.setErrorMsg("该工单已审批通过，无法编辑");
		// return chkRS;
		// }
		//
		// String siteId = order.getSite().getId();
		// String dfServId = order.getDefinitionServ().getId();
		// String servBusinessCode = StringUtils.trim((String)
		// paramMap.get("servBusinessCode"));
		// if (!order.getServBusinessCode().equals(servBusinessCode)) {
		// List<OrderEntity> orders =
		// orderDao.listBydfServIdAndServBusinessCodeAndSiteId(dfServId,
		// servBusinessCode,
		// siteId);
		//
		// if (orders.size() > 0) {
		// chkRS.setStatus(HttpStatus.SC_CONFLICT);
		// chkRS.setErrorMsg(MessageFormat.format(Messages.EXIST, "服务代码"));
		// return chkRS;
		// }
		// }
		//
		// String servBusinessName = StringUtils.trim((String)
		// paramMap.get("servBusinessName"));
		// if (!order.getServBusinessName().equals(servBusinessName)) {
		// String owner = order.getCreateUserLoginName();
		// List<OrderEntity> orders =
		// orderDao.listBydfServIdAndServBusinessNameAndSiteId(dfServId,
		// servBusinessName,
		// owner, siteId);
		// if (orders.size() > 0) {
		// chkRS.setStatus(HttpStatus.SC_CONFLICT);
		// chkRS.setErrorMsg(MessageFormat.format(Messages.EXIST, "服务名称"));
		// return chkRS;
		// }
		// }
		//
		// String dfSubServArchId = (String)
		// paramMap.get("definitionSubServArchId");
		// DefinitionSubServArchEntity selectedDfSubServArch = null;
		// List<DefinitionSubServArchEntity> dfSubServArchs =
		// definitionSubServArchDao
		// .listPrimarySubServArchName(dfServId);
		// for (DefinitionSubServArchEntity dfSubServArch : dfSubServArchs) {
		// if (dfSubServArchId.equals(dfSubServArch.getId())) {
		// selectedDfSubServArch = dfSubServArch;
		// break;
		// }
		// }
		// if (selectedDfSubServArch == null) {
		// chkRS.setStatus(HttpStatus.SC_GONE);
		// chkRS.setErrorMsg(MessageFormat.format(Messages.NOT_EXIST, "服务架构"));
		// return chkRS;
		// }
		//
		// String dfSubServUnitScaleId = (String)
		// paramMap.get("definitionSubServUnitScaleId");
		// DefinitionSubServUnitScaleEntity selectedDfSubServUnitScale = null;
		// List<DefinitionSubServUnitScaleEntity> dfSubServUnitScales =
		// definitionSubServUnitScaleDao
		// .listPrimarySubServUnitScaleName(dfServId);
		// for (DefinitionSubServUnitScaleEntity dfSubServUnitScale :
		// dfSubServUnitScales) {
		// if (dfSubServUnitScaleId.equals(dfSubServUnitScale.getId())) {
		// selectedDfSubServUnitScale = dfSubServUnitScale;
		// break;
		// }
		// }
		// if (selectedDfSubServUnitScale == null) {
		// chkRS.setStatus(HttpStatus.SC_GONE);
		// chkRS.setErrorMsg(MessageFormat.format(Messages.NOT_EXIST, "性能规模"));
		// return chkRS;
		// }
		//
		// String subServSoftwareImageId = (String)
		// paramMap.get("subServSoftwareImageId");
		// SubServSoftwareImageEntity selectedSubServSoftwareImage = null;
		// Map<String, Object> pSubServImageParamMap = new HashMap<String,
		// Object>();
		// pSubServImageParamMap.put("siteId", siteId);
		// pSubServImageParamMap.put("definitionServId", dfServId);
		// List<SubServSoftwareImageEntity> subServSoftwareImages =
		// subServSoftwareImageDao
		// .listSubServSoftwareImageVersion(pSubServImageParamMap);
		// for (SubServSoftwareImageEntity subServSoftwareImage :
		// subServSoftwareImages) {
		// if (subServSoftwareImageId.equals(subServSoftwareImage.getId())) {
		// selectedSubServSoftwareImage = subServSoftwareImage;
		// break;
		// }
		// }
		// if (selectedSubServSoftwareImage == null) {
		// chkRS.setStatus(HttpStatus.SC_GONE);
		// chkRS.setErrorMsg(MessageFormat.format(Messages.NOT_EXIST, "软件版本"));
		// return chkRS;
		// }
		// if (!selectedSubServSoftwareImage.isEnabled()) {
		// chkRS.setStatus(HttpStatus.SC_GONE);
		// chkRS.setErrorMsg(MessageFormat.format(Messages.DISABLED_NOT_SELECT,
		// "软件版本"));
		// return chkRS;
		// }
		//
		// String networkBandwidth = (String) paramMap.get("networkBandwidth");
		// if
		// (dictDao.getByDictTypeCodeAndDictCode(DictTypeConstants.NETWORK_BANDWIDTH,
		// networkBandwidth) == null) {
		// chkRS.setStatus(HttpStatus.SC_GONE);
		// chkRS.setErrorMsg(MessageFormat.format(Messages.NOT_EXIST, "网络带宽"));
		// return chkRS;
		// }
		//
		// String dataDirDeviceType = (String)
		// paramMap.get("dataDirDeviceType");
		// if
		// (dictDao.getByDictTypeCodeAndDictCode(DictTypeConstants.DATA_DIR_TYPE,
		// dataDirDeviceType) == null) {
		// chkRS.setStatus(HttpStatus.SC_GONE);
		// chkRS.setErrorMsg(MessageFormat.format(Messages.NOT_EXIST,
		// "数据目录类型"));
		// return chkRS;
		// }

		return chkRS;
	}

}
